<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="商家" prop="sellerId">
      <el-input v-model="dataForm.sellerId" placeholder="商家"></el-input>
    </el-form-item>
    <el-form-item label="同住人id" prop="peopleId">
      <el-input v-model="dataForm.peopleId" placeholder="同住人id"></el-input>
    </el-form-item>
    <el-form-item label="房间id" prop="floorRoomId">
      <el-input v-model="dataForm.floorRoomId" placeholder="房间id"></el-input>
    </el-form-item>
    <el-form-item label="单号" prop="singleId">
      <el-input v-model="dataForm.singleId" placeholder="单号"></el-input>
    </el-form-item>
    <el-form-item label="房号" prop="roomNum">
      <el-input v-model="dataForm.roomNum" placeholder="房号"></el-input>
    </el-form-item>
    <el-form-item label="原离店时间" prop="oldTime">
      <el-input v-model="dataForm.oldTime" placeholder="原离店时间"></el-input>
    </el-form-item>
    <el-form-item label="新离店时间" prop="newTime">
      <el-input v-model="dataForm.newTime" placeholder="新离店时间"></el-input>
    </el-form-item>
    <el-form-item label="原房价" prop="oldRoomPrice">
      <el-input v-model="dataForm.oldRoomPrice" placeholder="原房价"></el-input>
    </el-form-item>
    <el-form-item label="新房价" prop="newRoomPrice">
      <el-input v-model="dataForm.newRoomPrice" placeholder="新房价"></el-input>
    </el-form-item>
    <el-form-item label="本次付款方式" prop="paymentType">
      <el-input v-model="dataForm.paymentType" placeholder="本次付款方式"></el-input>
    </el-form-item>
    <el-form-item label="本次付款方式id" prop="paymentId">
      <el-input v-model="dataForm.paymentId" placeholder="本次付款方式id"></el-input>
    </el-form-item>
    <el-form-item label="本次付款金额" prop="payment">
      <el-input v-model="dataForm.payment" placeholder="本次付款金额"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="creatTime">
      <el-input v-model="dataForm.creatTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="原因" prop="remarks">
      <el-input v-model="dataForm.remarks" placeholder="原因"></el-input>
    </el-form-item>
    <el-form-item label="操作员" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="操作员"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          sellerId: '',
          peopleId: '',
          floorRoomId: '',
          singleId: '',
          roomNum: '',
          oldTime: '',
          newTime: '',
          oldRoomPrice: '',
          newRoomPrice: '',
          paymentType: '',
          paymentId: '',
          payment: '',
          creatTime: '',
          remarks: '',
          userId: ''
        },
        dataRule: {
          sellerId: [
            { required: true, message: '商家不能为空', trigger: 'blur' }
          ],
          peopleId: [
            { required: true, message: '同住人id不能为空', trigger: 'blur' }
          ],
          floorRoomId: [
            { required: true, message: '房间id不能为空', trigger: 'blur' }
          ],
          singleId: [
            { required: true, message: '单号不能为空', trigger: 'blur' }
          ],
          roomNum: [
            { required: true, message: '房号不能为空', trigger: 'blur' }
          ],
          oldTime: [
            { required: true, message: '原离店时间不能为空', trigger: 'blur' }
          ],
          newTime: [
            { required: true, message: '新离店时间不能为空', trigger: 'blur' }
          ],
          oldRoomPrice: [
            { required: true, message: '原房价不能为空', trigger: 'blur' }
          ],
          newRoomPrice: [
            { required: true, message: '新房价不能为空', trigger: 'blur' }
          ],
          paymentType: [
            { required: true, message: '本次付款方式不能为空', trigger: 'blur' }
          ],
          paymentId: [
            { required: true, message: '本次付款方式id不能为空', trigger: 'blur' }
          ],
          payment: [
            { required: true, message: '本次付款金额不能为空', trigger: 'blur' }
          ],
          creatTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          remarks: [
            { required: true, message: '原因不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '操作员不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomcontinuedrecord/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.sellerId = data.tHotelFloorRoomContinuedRecord.sellerId
                this.dataForm.peopleId = data.tHotelFloorRoomContinuedRecord.peopleId
                this.dataForm.floorRoomId = data.tHotelFloorRoomContinuedRecord.floorRoomId
                this.dataForm.singleId = data.tHotelFloorRoomContinuedRecord.singleId
                this.dataForm.roomNum = data.tHotelFloorRoomContinuedRecord.roomNum
                this.dataForm.oldTime = data.tHotelFloorRoomContinuedRecord.oldTime
                this.dataForm.newTime = data.tHotelFloorRoomContinuedRecord.newTime
                this.dataForm.oldRoomPrice = data.tHotelFloorRoomContinuedRecord.oldRoomPrice
                this.dataForm.newRoomPrice = data.tHotelFloorRoomContinuedRecord.newRoomPrice
                this.dataForm.paymentType = data.tHotelFloorRoomContinuedRecord.paymentType
                this.dataForm.paymentId = data.tHotelFloorRoomContinuedRecord.paymentId
                this.dataForm.payment = data.tHotelFloorRoomContinuedRecord.payment
                this.dataForm.creatTime = data.tHotelFloorRoomContinuedRecord.creatTime
                this.dataForm.remarks = data.tHotelFloorRoomContinuedRecord.remarks
                this.dataForm.userId = data.tHotelFloorRoomContinuedRecord.userId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hotel/thotelfloorroomcontinuedrecord/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sellerId': this.dataForm.sellerId,
                'peopleId': this.dataForm.peopleId,
                'floorRoomId': this.dataForm.floorRoomId,
                'singleId': this.dataForm.singleId,
                'roomNum': this.dataForm.roomNum,
                'oldTime': this.dataForm.oldTime,
                'newTime': this.dataForm.newTime,
                'oldRoomPrice': this.dataForm.oldRoomPrice,
                'newRoomPrice': this.dataForm.newRoomPrice,
                'paymentType': this.dataForm.paymentType,
                'paymentId': this.dataForm.paymentId,
                'payment': this.dataForm.payment,
                'creatTime': this.dataForm.creatTime,
                'remarks': this.dataForm.remarks,
                'userId': this.dataForm.userId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
